<template>
	<view class="page">
		<v-tabs height="90rpx"
		lineHeight="6rpx" 
		v-model="current" 
		fontSize="36rpx" 
		:tabs="tabs" 
		@change="changeTab"  
		activeColor="#00aa7f"
		:scroll="false"
		color="#515151" 
		lineColor="#00aa7f"></v-tabs>
		<view class="list" v-if="current==0">
			<view class="list-item" v-for="(item,index) in orderList":key="index">
				<uni-list :border="false" >
					<uni-list-item  :isBorder="true" :extraIcon="extraIcon" showExtraIcon="true" >
						<view  class="list-item-column" >
							<view class="slot-box">
								<text class="slot-text">本单收入：{{item.commission}}</text>
							</view>
							<text class="uni-list-item__content-note">下单时间：{{item.placeOrderTime}}</text>
						</view>
					</uni-list-item>
					<uni-list-item  :isBorder="true" :extraIcon="extraIcon1" showExtraIcon="true" >
						<view  class="list-item-column" >
							<view class="">
								取货地址
							</view>
							<view class="slot-box">
								<text class="slot-text">{{item.place}}</text>
							</view>
						</view>
						<view slot="right">
							<zywork-icon  type="iconditu" color="#00aa7f" :size="50" />
						</view>
					</uni-list-item>
					<uni-list-item  :isBorder="true" :extraIcon="extraIcon2"  showExtraIcon="true">
						<view  class="list-item-column" >
							<view class="">
								配送地址
							</view>
							<view class="slot-box">
								<text class="slot-text">{{item.storiedBuilding}}{{item.area}}</text>
							</view>
						</view>
						<view slot="right">
							<zywork-icon  type="iconditu" color="#00aa7f" :size="50" />
						</view>
					</uni-list-item>
					<uni-list-item  :isBorder="true" :extraIcon="{color: '#ffb907',size: 50,type: 'iconicon'}"  showExtraIcon="true">
						<view  class="list-item-column" >
							<view class="">
								订单号
							</view>
							<view class="slot-box">
								<text class="slot-text">{{item.orderId}}</text>
							</view>
						</view>
					</uni-list-item>
					<view v-if="current==0" class="add-order-btn"  @click="addOrderBtn(item)">
						立即抢单
					</view>
					<view v-else class="add-order-btn" @click="getOrderInfo(item)">
						查看订单详情
					</view>
				</uni-list>
			</view>
			<view v-if="messageAlert" class="zy-message-alert">
				已经到底了
			</view>
			<view v-else class="zy-message-alert">
				加载更多数据
			</view>
		</view>
		<view class="list" v-if="current>0">
			<view  class="list-item" v-for="(item,indexs) in orderCourierList" :key="indexs">
				<uni-list :border="false" >
					<uni-list-item  :isBorder="true" :extraIcon="extraIcon" showExtraIcon="true" >
						<view  class="list-item-column" >
							<view class="slot-box">
								<text class="slot-text">本单收入：{{item.schoolOrderCommission}}</text>
							</view>
							<text class="uni-list-item__content-note">下单时间：{{item.schoolOrderPlaceOrderTime}}</text>
						</view>
					</uni-list-item>
					<uni-list-item  :isBorder="true" :extraIcon="extraIcon1" showExtraIcon="true" >
						<view  class="list-item-column" >
							<view class="">
								取货地址
							</view>
							<view class="slot-box">
								<text class="slot-text">{{item.schoolOrderPlace}}</text>
							</view>
						</view>
						<view slot="right">
							<zywork-icon  type="iconditu" color="#00aa7f" :size="50" />
						</view>
					</uni-list-item>
					<uni-list-item  :isBorder="true" :extraIcon="extraIcon2"  showExtraIcon="true">
						<view  class="list-item-column" >
							<view class="">
								配送地址
							</view>
							<view class="slot-box">
								<text class="slot-text">{{item.schoolOrderAddressStoriedBuilding}}{{item.schoolOrderAddressArea}}</text>
							</view>
						</view>
						<view slot="right">
							<zywork-icon  type="iconditu" color="#00aa7f" :size="50" />
						</view>
					</uni-list-item>
					<uni-list-item  :isBorder="true" :extraIcon="{color: '#ffb907',size: 50,type: 'iconicon'}"  showExtraIcon="true">
						<view  class="list-item-column" >
							<view class="">
								订单号
							</view>
							<view class="slot-box">
								<text class="slot-text">{{item.schoolOrderId}}</text>
							</view>
						</view>
					</uni-list-item>
					
					<view class="zy-row">
						<view class="add-order-btn" @click="getOrderInfo(item)">
							查看订单详情
						</view>
						<view v-if="item.schoolOrderStatus==1" class="add-order-btn" style="background-color: #00AA7F;" @click="getDispatching(item)">
							已取件开始配送
						</view>
						<!-- <view v-if="item.schoolOrderStatus==2" class="add-order-btn" style="background-color: #ff6233;">
							等待买家确认
						</view> -->
					</view>
				</uni-list>
			</view>
		</view>
	</view>
</template>

<script>
	import vTabs from '@/components/v-tabs/v-tabs.vue'
	import uniList from '@/components/uni-list/uni-list.vue'
	import uniListItem from '@/components/uni-list-item/uni-list-item.vue'
	import zyworkIcon from '@/components/zywork-icon/zywork-icon.vue'
	import * as ResponseStatus from '@/common/response-status.js'
	import {
		showInfoToast,
		doGet,
		doPostJson,
		MY_SHARE_CODE,
		SHARE_CODE_PAGE_IMG,
		SHARE_TITLE,
		SHARE_CODE,
		FRONT_BASE_URL,
		LOCAL_FILE_STORAGE,
		USER_ROLES,
		USER_ID,
		USER_NICKNAME,
		USER_HEADICON,
		HOST_ROOM_INFO,
		USER_SCHOOL
	} from '@/common/util.js'
	export default {
		components: {
			vTabs
		},
		data() {
			return {
				extraIcon: {
					color: '#ffcc00',
					size: 50,
					type: 'iconshouru'
				},
				extraIcon1: {
					color: '#00aa7f',
					size: 50,
					type: 'iconquzhong'
				},
				extraIcon2: {
					color: '#ff5500',
					size: 50,
					type: 'iconsong'
				},
				current: 0,
				tabs: [
				'待接单',
				'已接单',
				'配送中',
				'已送达',
				],
				pager:{
					"pageNo": 0,
					"pageSize": 10,
					"schoolId": uni.getStorageSync(USER_SCHOOL),
					"status":0
				},
				canPullDownRefresh: true,
				onPullDownRefresh: false,
				showLoading: false,
				orderList:[],
				orderCourierList:[],
				messageAlert:false,
			};
		},
		onLoad() {
			// this.getSchoolOrder('refresh');
			//swiper高度自适应
		},
		onShow() {
			this.getSchoolOrder('refresh');
			
		},
		onPullDownRefresh() {
			this.getSchoolOrder('refresh');
			setTimeout(function() {
				uni.stopPullDownRefresh()
			}, 1000)
		},
		//加载更多
		onReachBottom(){
			uni.showLoading({
				title: '正在加载'
			})
			this.showLoading = true
			this.pager.pageNo+=1
			this.getSchoolOrder('add');
		},
		methods:{
			getOrderInfo(item){
				item.status = 0
				var orderCourier = JSON.stringify(item); // 这里转换成 字符串
				uni.navigateTo({
					url:"/pages/order/createOrder?orderCourier="+orderCourier
				})
			},
			getDispatching(item){
				let url ="/school-order/user/orderUser/distribution/";
				doGet(url+item.schoolOrderId, {}, {}, true).then(response => {
					let [error, res] = response;
					if (res.data.code === ResponseStatus.OK) {
						showInfoToast("开始配送")
						this.getSchoolOrder('refresh');
					} else {
						showInfoToast(res.data.message)
					}
				}).catch(err => {
					console.log(err)
				})
			},
			changeTab(index){
				this.current = index;
				this.pager.status = index;
				this.getSchoolOrder('refresh');
			},
			addOrderBtn(item){
				doPostJson('/school-order/user/courier/order/'+item.orderId, {}, {}, true).then(response => {
					let [err, res] = response
					if (res.data.code === ResponseStatus.OK) {
						showInfoToast(res.data.message)
						this.getSchoolOrder('refresh');
					}else{
						showInfoToast(res.data.message)
					}
				}).catch(error => {})
			},
			getSchoolOrder(type){
				if(type === 'refresh'){
					this.pager.pageNo=1
				}
				if(this.current==0){
					//待接单信息
					doPostJson('/school-order/any/courier/hall', this.pager, {}, true).then(response => {
						let [err, res] = response
						if (res.data.code === ResponseStatus.OK) {
							if (type === 'refresh') {
								this.orderList = res.data.data;
							} else {
								this.orderList= this.orderList.concat(res.data.data)
							}
							if(res.data.data.length==0){
								this.messageAlert = true;
							}
							if (this.onPullDownRefresh) {
								this.onPullDownRefresh = false
								uni.hideLoading()
							}
							if (this.showLoading) {
								this.showLoading = false
								uni.hideLoading()
							}
						}
					}).catch(error => {})
				}else {
					this.pager.schoolOrderSchoolId = this.pager.schoolId
					this.pager.schoolOrderStatus = this.pager.status
					doPostJson('/school-order-address-user/user/pager-cond-courier', this.pager, {}, true).then(response => {
						let [err, res] = response
						if (res.data.code === ResponseStatus.OK) {
							if (type === 'refresh') {
								this.orderCourierList = res.data.data.rows;
							} else {
								this.orderCourierList= this.orderCourierList.concat(res.data.data.rows)
							}
							if(res.data.data.rows.length==0){
								this.messageAlert = true;
							}else{
								this.messageAlert = false;
							}
							if (this.onPullDownRefresh) {
								this.onPullDownRefresh = false
								uni.hideLoading()
							}
							if (this.showLoading) {
								this.showLoading = false
								uni.hideLoading()
							}
						}
					}).catch(error => {})
				}
				
			}
		}
	}
</script>

<style lang="scss">
	@import '@/common/zywork-main.scss';
	.page{
		width: 100%;
		height: 100%;
		background-color: #f4f4f4;
	}
	.zy-message-alert{
		width: 100%;
		text-align: center;
		font-size: $font-lg;
	}
	.zy-row{
		@include flex-center-row;
		align-items: center;
		justify-content: space-around;
	}
	.list{
		@include flex-center-column;
		@include padding;
		background-color: #f4f4f4;
		align-items: center;
		.list-item{
			padding: 10rpx 10rpx;
			margin: 10rpx 0rpx;
			width: 100%;
			border-radius: 35rpx;
			border: solid 1rpx #EEEEEE;
			background-color: $primary-backcolor;
			.list-item-column{
				@include flex-center-column;
			}
			.add-order-btn{
				margin: 20rpx auto;
				width: 260rpx;
				height: 80rpx;
				line-height: 80rpx;
				background: #ffaa00;
				text-align: center;
				border-radius: 15rpx;
				color: $primary-color;
			}
			
		}
		
	}
	.slot-box {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		align-items: center;
		padding: 10rpx 0rpx;
	}
	.slot-text{
		color: #3b4144;
		font-size: $font-base;
	}
</style>
